﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace FB.Utilities
{

    public static class Common
    {
        public static string GetYoutubeThumb(string youtubeID)
        {
            return "http://i.ytimg.com/vi/" + youtubeID + "/mqdefault.jpg";
        }

        public static int CountIEnumberable(this IEnumerable source)
        {
            int res = 0;
            foreach (var item in source)
            {
                res++;
            }
            return res;
        }

        /// <summary>
        /// Ham bo dau tieng viet
        /// </summary>
        /// <param name="str">input string</param>
        /// <returns>return string</returns>
        public static string RemoveSign(string str)
        {
            string[] signs = new string[] { 
                            "aAeEoOuUiIdDyY",
                            "áàạảãâấầậẩẫăắằặẳẵ",
                            "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
                            "éèẹẻẽêếềệểễ",
                            "ÉÈẸẺẼÊẾỀỆỂỄ",
                            "óòọỏõôốồộổỗơớờợởỡ",
                            "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
                            "úùụủũưứừựửữ",
                            "ÚÙỤỦŨƯỨỪỰỬỮ",
                            "íìịỉĩ",
                            "ÍÌỊỈĨ",
                            "đ",
                            "Đ",
                            "ýỳỵỷỹ",
                            "ÝỲỴỶỸ"
            };
            for (int i = 1; i < signs.Length; i++)
            {
                for (int j = 0; j < signs[i].Length; j++)
                {
                    str = str.Replace(signs[i][j], signs[0][i - 1]);
                }
            }
            return str;
        }

        public static string FormatAlertMsg(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append("alert('");
            sb.Append(msg);
            sb.Append("');");
            sb.Append("</script>");
            return sb.ToString();
        }
        public static string Second2Munite(double second)
        {
            StringBuilder sb = new StringBuilder();
            TimeSpan time = TimeSpan.FromSeconds(second);
            if (time.Hours > 0)
            {
                sb.Append(time.Hours);
                sb.Append(":");
            }
            if (time.Minutes > 0)
            {
                sb.Append(time.Minutes);
                sb.Append(":");
            }
            sb.AppendFormat("{0:00}", time.Seconds);
            return sb.ToString();
        }
        public static string Second2Munite(string second)
        {
            double Temp = 0;
            if (double.TryParse(second, out Temp))
            {
                return Second2Munite(Temp);
            }
            return "";
        }
    }

    public class ReturnValue<T>
    {
        private T _retValue;
        private string _msg;
        public ReturnValue(T inA, string inMgs)
        {
            _retValue = inA;
            _msg = inMgs;
        }

        public T RetValue
        {
            get { return _retValue; }
            set { _retValue = value; }
        }
        public string Msg
        {
            get { return _msg; }
            set { _msg = value; }
        }

    }
}
